package mo.leetcode_top;

import mo.common.TreeNode;

public class L98 {

    public boolean isValidBST(TreeNode root) {
        if (root == null) {
            return true;
        }
        return validNode(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    private boolean validNode(TreeNode node, long min, long max) {
        if (node == null) {
            return true;
        }
        if (node.val <= min || node.val >= max) {
            return false;
        }
        return validNode(node.left, min, node.val) && validNode(node.right, node.val, max);
    }

}
